package com.jacen.fzxs.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.jacen.fzxs.dao.IDictItemDao;
import com.jacen.fzxs.entity.DictItemEntity;
import com.jacen.fzxs.util.SqlCondition;
import com.jacen.fzxs.util.Utils;


/**
 * 字典项
 * @author Jacen
 * 2014年9月3日 下午2:30:40
 */
@Repository
public class DictItemDao extends BaseDao<DictItemEntity> implements IDictItemDao {

	@Override
	public List<DictItemEntity> getList(Map<String, String> params) {
		// TODO Auto-generated method stub
		SqlCondition cond = getPageCondition(params);
		String sql = "select * from t_dictitem where 1=1 %s order by itemName  ";
		sql = String.format(sql,cond.getCondition());
		return executeForList(sql,cond.getParams().toArray());
	}
	
	private SqlCondition getPageCondition(
			Map<String, ? extends Object> mapParams) {
		SqlCondition cond = new SqlCondition();
		if (Utils.paramIsNotEmpty(mapParams.get("groupName")))
			cond.and().equal("groupName", mapParams.get("groupName"));
		if (Utils.paramIsNotEmpty(mapParams.get("itemValue")))
			cond.and().like("itemValue", mapParams.get("itemValue"));
		return cond;
	}

	@Override
	public DictItemEntity getItemByGroupAndName(String groupName, Integer trade) {
		String sql = "select * from t_dictitem where groupname = '"+groupName+"'  and itemname="+trade;
		return executeForObject(sql);
	}
	

	

}
